namespace MediaWiki\Session;
+use Config;
use MediaWikiTestCase;
use User;
use Wikimedia\TestingAccessWrapper;
class SessionBackendTest extends MediaWikiTestCase {
const SESSIONID = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
+ /** @var SessionManager */
protected $manager;
+
+ /** @var Config */
protected $config;
+
+ /** @var SessionProvider */
protected $provider;
+
+ /** @var TestBagOStuff */
protected $store;
protected $onSessionMetadataCalled = false;
* Returns a non-persistent backend that thinks it has at least one session active
* @param User|null $user
* @param string $id
+ * @return SessionBackend
*/
protected function getBackend( User $user = null, $id = null ) {
if ( !$this->config ) {
$this->assertSame( $info->forceHTTPS(), $backend->shouldForceHTTPS() );
$expire = time() + 100;
- $this->store->setSessionMeta( self::SESSIONID, [ 'expires' => $expire ], 2 );
+ $this->store->setSessionMeta( self::SESSIONID, [ 'expires' => $expire ] );
$info = new SessionInfo( SessionInfo::MIN_PRIORITY, [
'provider' => $this->provider,
/**
* @param string $id Session ID
* @param array $data Session data
- * @param int $expiry
- * @param User $user User for metadata
*/
- public function setSessionData( $id, array $data, $expiry = 0, User $user = null ) {
- $this->setSession( $id, [ 'data' => $data ], $expiry, $user );
+ public function setSessionData( $id, array $data ) {
+ $this->setSession( $id, [ 'data' => $data ] );
}
/**
* @param string $id Session ID
* @param array $metadata Session metadata
- * @param int $expiry
*/
- public function setSessionMeta( $id, array $metadata, $expiry = 0 ) {
- $this->setSession( $id, [ 'metadata' => $metadata ], $expiry );
+ public function setSessionMeta( $id, array $metadata ) {
+ $this->setSession( $id, [ 'metadata' => $metadata ] );
}
/**
* @param string $id Session ID
* @param array $blob Session metadata and data
- * @param int $expiry
- * @param User $user User for metadata
*/
- public function setSession( $id, array $blob, $expiry = 0, User $user = null ) {
+ public function setSession( $id, array $blob ) {
$blob += [
'data' => [],
'metadata' => [],
];
$blob['metadata'] += [
- 'userId' => $user ? $user->getId() : 0,
- 'userName' => $user ? $user->getName() : null,
- 'userToken' => $user ? $user->getToken( true ) : null,
+ 'userId' => 0,
+ 'userName' => null,
+ 'userToken' => null,
'provider' => 'DummySessionProvider',
];
- $this->setRawSession( $id, $blob, $expiry, $user );
+ $this->setRawSession( $id, $blob );
}
/**
* @param string $id Session ID
* @param array|mixed $blob Session metadata and data
- * @param int $expiry
*/
- public function setRawSession( $id, $blob, $expiry = 0 ) {
- if ( $expiry <= 0 ) {
- $expiry = \RequestContext::getMain()->getConfig()->get( 'ObjectCacheSessionExpiry' );
- }
-
+ public function setRawSession( $id, $blob ) {
+ $expiry = \RequestContext::getMain()->getConfig()->get( 'ObjectCacheSessionExpiry' );
$this->set( $this->makeKey( 'MWSession', $id ), $blob, $expiry );
}